const fs = require('fs')

/**
 *读取router文件夹下的文件，动态注册路由对象
 *
 * @param {*} app
 */
function autoRegisterRoutes (app) {
  const files = fs.readdirSync(__dirname)
  for (const file of files) {
    if (!file.endsWith('.router.js')) continue
    const router = require(`./${file}`)
    app.use(router.routes())
    app.use(router.allowedMethods())
  }
}
module.exports = autoRegisterRoutes